#pragma once
#include"event/Object.h"
#include"jsonCpp/json.h"
#include"gameLogic/Myvec.h"
#include<string>
#include<map>

struct Player {
	long long sock = 0;
	int id = 1;
	int sceneId = 0;
	std::string name = "";
	int64_t time = 0;
};

class UserBaseController:public Object
{
public:
	UserBaseController(Object* master);
	~UserBaseController();

	uint64_t getTime();

	void C2S_Login(Json::Value& message);

	void C2S_Register_User(Json::Value& message);

	void C2S_HeartBeat(Json::Value& message);

	void C2S_UpdatePos(Json::Value& message);

	void C2S_UpdateVelocity(Json::Value& message);

	void C2S_EnterScane(Json::Value& message);

	void C2S_CheckNearPlayers(Json::Value& message);

	void addPlayer(long long sock,int id, std::string name);

	void removePlayer(long long id);

	void updatePlayerTime(const long long& id);

	void onPlayerLeave(Json::Value& message);

	Myvec jsonToMyVec(Json::Value& data);

	int geUserIdBySock(int64_t sock);

	std::string getPlayerName(int id);
	const Player* getPlayer(int id);
private:
	void update(float dt);

	Object* m_master;

	std::map<int, Player> m_players;
	std::map<int64_t, int> m_sockMapId;

	static int global_playerId;
};

